package day02.practice;

import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class PersonTest {
    public static void main(String[] args) {
        //1.创建TreeSet集合存储Person对象
        TreeSet<Person> ts = new TreeSet<>(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                //o2的总成绩-o1的总成绩
                return (int)(o2.getMath()+ o2.getChinese()+o2.getEnglish()-(o1.getMath()+ o1.getChinese()+o1.getEnglish()));
            }

        });
        //2.键盘输入
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入第"+(i+1)+"个同学的名字：");
            String name = sc.next();
            System.out.println("请输入第"+(i+1)+"个同学语文成绩：");
            double x = sc.nextDouble();
            System.out.println("请输入第"+(i+1)+"个同学数学成绩：");
            double y = sc.nextDouble();
            System.out.println("请输入第"+(i+1)+"个同学英语成绩：");
            double z = sc.nextDouble();

            Person person = new Person(name, x, y, z);
            //Person封装进Treeset集合
            ts.add(person);
        }
        for (Person person : ts) {
            System.out.println(person);
        }
        }

        }
